using System;
using System.Collections.Generic;
using System.Data;
using Confcloud.Core.Architecture;
using Smarly.Core.Database;

namespace Confcloud.Email
{
	public partial class EmailTemplate : RestObject<Confcloud.Email.EmailTemplate>
	{
		public int EmailTemplateId { get; set; }

		public Guid? AccountId { get; set; }
		public int? EventId { get; set; }

		public string Name { get; set; }
		public string LanguageId { get; set; }

		public string Subject { get; set; }
		public string Body { get; set; }
		public TemplateType Type { get; set; }

		public string Data { get; set; }

		public enum TemplateType
		{
			Body,
			Html,
		}


		#region Overrides of RestObject<EmailTemplate>

		public override Confcloud.Email.EmailTemplate Get()
		{
				var sqlParams = new List<SpParam>
				                	{
				                		new SpParam {Name = "@name", Type = DbType.String, Value = Name},
				                		new SpParam {Name = "@accountId", Type = DbType.Guid, Value = AccountId},
				                		new SpParam {Name = "@languageId", Type = DbType.String, Value = LanguageId},
				                		new SpParam {Name = "@eventId", Type = DbType.Int32, Value = EventId},
				                	};


				return SqlRepository.ExecuteProcedureReader("[dbo].[Public_2_EmailTemplate_Get]",
																					sqlParams, OnSqlInfoMessage,
				                                  (reader) =>
				                                  	{
				                                  		while (reader.Read())
				                                  		{
				                                  			Subject = reader.GetStringOrNull("Subject");
				                                  			Body = reader.GetStringOrNull("Body");
				                                  			Type = (TemplateType) reader.GetByteOrDefault("Type");

				                                  		}
				                                  		return this;
				                                  	});
		}

		public override Confcloud.Email.EmailTemplate Post()
		{
			throw new NotImplementedException();
		}

		public override Confcloud.Email.EmailTemplate Put()
		{
			throw new NotImplementedException();
		}

		public override Confcloud.Email.EmailTemplate Delete()
		{
			throw new NotImplementedException();
		}

		#endregion
	}

}